# Maintainer: Ian Dunbar-Hall <ian.dunbarhall@gmail.com>
pkgname=bomctl
pkgver=0.1.9
pkgrel=1
pkgdesc="Format agnostic SBOM tooling"
url="https://github.com/bomctl/bomctl"
# loongarch64: incompatible modernc.org/sqlite
arch="all !loongarch64"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/bomctl/bomctl/archive/refs/tags/v$pkgver.tar.gz"
options="chmod-clean net"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export major_minor_patch=$(echo $pkgver | grep -o '[0-9]*\.[0-9]*\.[0-9]*' | head -n 1)
	export major=$(echo $major_minor_patch | cut -d'.' -f1)
	export minor=$(echo $major_minor_patch | cut -d'.' -f2)
	export patch=$(echo $major_minor_patch | cut -d'.' -f3)

	mkdir build
	go build -o build/ \
		-trimpath \
		-ldflags="-s -w
			-X=github.com/bomctl/bomctl/cmd.VersionMajor=$major
			-X=github.com/bomctl/bomctl/cmd.VersionMinor=$minor
			-X=github.com/bomctl/bomctl/cmd.VersionPatch=$patch
			-X=github.com/bomctl/bomctl/cmd.BuildDate=alpine"

	for i in bash fish zsh; do
		"$builddir"/build/bomctl completion $i > "$builddir"/bomctl.$i
	done
}

check() {
	"$builddir"/build/bomctl --version
}

package() {
	install -Dm755 "$builddir"/build/bomctl "$pkgdir"/usr/bin/bomctl
	install -Dm644 "$builddir"/bomctl.bash "$pkgdir"/usr/share/bash-completion/completions/bomctl
	install -Dm644 "$builddir"/bomctl.fish "$pkgdir"/usr/share/fish/vendor_completions.d/bomctl.fish
	install -Dm644 "$builddir"/bomctl.zsh "$pkgdir"/usr/share/zsh/site-functions/_bomctl
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

sha512sums="
7870d422869c494303bbcb6f1a930945e2abdd07e38222201d0e0484729edcc4f291e65264e6ee8d94b57a10e0b8c721a8100bd669e4fff9721042033d3518b9  bomctl-0.1.9.tar.gz
"
